﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MovieRental.Charts
{
    public class TimeDataSeries<TData> where TData : IComparable<TData>, new()
    {
        private SortedDictionary<DateTime, TData> _data = new SortedDictionary<DateTime, TData>();

        public void AddPoint(DateTime time, TData point)
        {
            _data.Add(time, point);
        }

        public IEnumerable<KeyValuePair<DateTime, TData>> Points
        {
            get { return _data; }
        }

        public DateTime MinTime
        {
            get { return (!_data.Any()) ? DateTime.MinValue : _data.First().Key; }
        }

        public DateTime MaxTime
        {
            get { return (!_data.Any()) ? DateTime.MaxValue : _data.Last().Key; }
        }

        public TData MinValue
        {
            get { return (!_data.Any()) ? new TData() : _data.Values.OrderBy(x => x).First(); }
        }

        public TData MaxValue
        {
            get { return (!_data.Any()) ? new TData() : _data.Values.OrderBy(x => x).Last(); }
        }

    }
}
